package com.ruoyi.stream.framework.model.configBuilder.single;

import com.ruoyi.stream.framework.core.workDomain.SingleIOTask;
import com.ruoyi.stream.framework.core.workDomain.io.ConsumeIO;
import com.ruoyi.stream.framework.core.workDomain.io.IOBehavior;
import com.ruoyi.stream.framework.core.workDomain.io.consumeHandlers.CommonConsume;
import com.ruoyi.stream.framework.core.workDomain.io.ioBehavior.SingleCancelBehavior;
import com.ruoyi.stream.framework.core.workDomain.io.ioBehavior.PauseBehavior;
import com.ruoyi.stream.framework.core.workDomain.io.ioBehavior.ProductIOResource;
import com.ruoyi.stream.framework.model.configBuilder.IOTaskConfig;
import io.netty.channel.Channel;

import java.io.InputStream;

public class SingleIOTaskConfig extends IOTaskConfig<SingleIOTask> {

    private int readCacheLength;

    private IOBehavior productBehavior = new ProductIOResource();

    private IOBehavior cancelBehavior = new SingleCancelBehavior();

    private IOBehavior pauseBehavior = new PauseBehavior();

    private ConsumeIO consumeIO = new CommonConsume();

    private InputStream inputStream;

    private Channel outputChannel;

    public ConsumeIO getConsumeIO() {
        return consumeIO;
    }


    public void setConsumeIO(ConsumeIO consumeIO) {
        this.consumeIO = consumeIO;
    }

    private int fullLength;

    private int skipLength;

    public int getReadCacheLength() {
        return readCacheLength;
    }

    public void setReadCacheLength(int readCacheLength) {
        this.readCacheLength = readCacheLength;
    }

    public IOBehavior getProductBehavior() {
        return productBehavior;
    }

    public void setProductBehavior(IOBehavior productBehavior) {
        this.productBehavior = productBehavior;
    }

    public IOBehavior getCancelBehavior() {
        return cancelBehavior;
    }

    public void setCancelBehavior(IOBehavior cancelBehavior) {
        this.cancelBehavior = cancelBehavior;
    }

    public IOBehavior getPauseBehavior() {
        return pauseBehavior;
    }

    public void setPauseBehavior(IOBehavior pauseBehavior) {
        this.pauseBehavior = pauseBehavior;
    }

    public int getFullLength() {
        if (fullLength == 0){
            return -1;
        }
        return fullLength;
    }

    public void setFullLength(int fullLength) {
        this.fullLength = fullLength;
    }

    public int getSkipLength() {
        return skipLength;
    }

    public void setSkipLength(int skipLength) {
        this.skipLength = skipLength;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public void setOutputChannel(Channel outputChannel) {
        this.outputChannel = outputChannel;
    }

    @Override
    public SingleIOTask getTask() {
        return new SingleIOTask(inputStream,this.readCacheLength,this.cancelBehavior,this.productBehavior,
                this.pauseBehavior,this.consumeIO,this.outputChannel);
    }
}
